// PreviewPane.cpp : implementation file
//

#include "stdafx.h"
#include "OutlookUIDemo.h"
#include "PreviewPane.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define CAPT_MAX_HEIGHT	35
#define CAPT_MIN_HEIGHT 5

#define TEXT_BOLD_LEFT	4
#define TEXT_NORM_LEFT	75
#define TEXT_LINE_ONE	4
#define TEXT_LINE_TWO	18

/////////////////////////////////////////////////////////////////////////////
// CPreviewPane

IMPLEMENT_DYNCREATE(CPreviewPane, CView)

CPreviewPane::CPreviewPane()
{
	m_strTitle1 = _T("Message:");
	m_strDescp1 = _T("Some words about this message");
	m_strTitle2 = _T("Content:");
	m_strDescp2 = _T("This message contains nothing special.");
	
	m_strViewMessage = _T("This area can be used for preview info...");
	m_clrViewMessage = RGB(255,255,255);

	m_bMax = TRUE;

	theApp.UpdateFont(m_NormFont);
	theApp.UpdateFont(m_BoldFont, FW_BOLD);
}

CPreviewPane::~CPreviewPane()
{
}


BEGIN_MESSAGE_MAP(CPreviewPane, CView)
	//{{AFX_MSG_MAP(CPreviewPane)
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPreviewPane drawing

void CPreviewPane::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();

	// TODO: add draw code here
	GetWindowRect(&m_rcCaption);
	ScreenToClient(&m_rcCaption);
	m_rcView.CopyRect(m_rcCaption);

	m_rcCaption.bottom = m_bMax?CAPT_MAX_HEIGHT:CAPT_MIN_HEIGHT;
	m_rcView.top = m_rcCaption.bottom;

	pDC->FillSolidRect(m_rcCaption, ::GetSysColor(COLOR_BTNFACE));
	pDC->Draw3dRect(m_rcCaption, ::GetSysColor(COLOR_BTNHIGHLIGHT),
		::GetSysColor(COLOR_BTNSHADOW));
	pDC->SetBkMode(TRANSPARENT);

	if (m_bMax)
	{
		pDC->SelectObject(&m_BoldFont);

		pDC->TextOut(TEXT_BOLD_LEFT, TEXT_LINE_ONE, m_strTitle1);
		pDC->TextOut(TEXT_BOLD_LEFT, TEXT_LINE_TWO, m_strTitle2);

		pDC->SelectObject(&m_NormFont);
		pDC->TextOut(TEXT_NORM_LEFT, TEXT_LINE_ONE, m_strDescp1);
		pDC->TextOut(TEXT_NORM_LEFT, TEXT_LINE_TWO, m_strDescp2);
	}

	int y = 5+(m_bMax?33:0);
	pDC->SelectObject(&m_NormFont);
	pDC->TextOut(5, y, m_strViewMessage);
}

/////////////////////////////////////////////////////////////////////////////
// CPreviewPane diagnostics

#ifdef _DEBUG
void CPreviewPane::AssertValid() const
{
	CView::AssertValid();
}

void CPreviewPane::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPreviewPane message handlers

void CPreviewPane::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// Toggle caption.
	if (m_rcCaption.PtInRect(point)) {
		m_bMax = !m_bMax;
		Invalidate();
	}
	
	CView::OnLButtonDblClk(nFlags, point);
}
